import type { CallBack, FailComposer, ReactiverLike } from "../types";
import Composer from "./composer";

export default class Fail extends Composer implements FailComposer {
  private fail!: CallBack<any, CallBack>;

  constructor(reactiver: ReactiverLike) {
    super(reactiver);
  }

  set(val: CallBack, caller: any = this): void {
    this.fail = (params) => {
      return val.bind(caller, ...params);
    };
  }

  run(...args: Array<any>) {
    this.fail?.(args)();
  }

  destroy(arg?: any): void {}
}
